// https://mongoosejs.com/docs/
const Power = require("../model/powermodel").Power;
const mongoose = require('mongoose');

const atlasuri = "mongodb+srv://admin:ESPL888espl@cluster0-edjgm.mongodb.net/test?authSource=admin&replicaSet=Cluster0-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true";
const webdb = "mongodb://localhost:27017/powerdb?readPreference=primary&appname=MongoDB%20Compass&ssl=false"

db = atlasuri //test local and/or cloud db

mongoose.connect(db, {useCreateIndex: true,useNewUrlParser: true});

const p = new Power({
  'voltage': "134",
  "current": "2.5",
  "temperature":"45",
  "runTime":"134"
})

p.save(function (err, callback) {
  if (err) return console.error(err);
  console.log(callback)
});


Power.find(function (err, data) {
  if (err) return console.error(err);
  console.log(data);
})
